<%@ page
	import="java.util.*,com.db.tracker.vo.*,java.util.*,com.db.tracker.util.*,java.text.*,java.io.*"%>
<%@ page import="com.db.tracker.vo.ReleaseVO"%>
<%
		try {
		System.out
		.println("XXXXXXXXXXXXXXXXX START LOADING JSP PAGE XXXXXXXXXXXXXXXX");
		session = request.getSession();
		//		System.out.println("user_id..main"+ session.getAttribute("USER_ID"));

		if (session.getAttribute("USER_ID") == null
		|| !((String) session.getAttribute("SESSION_ID"))
				.equals(session.getId())) {

			try {
		response.sendRedirect("LoginPage.jsp");
			} catch (IOException ioe) {
		ioe.printStackTrace();
			}

		} else {
			String userid = (String) session.getAttribute("USER_ID") == null ? ""
			: (String) session.getAttribute("USER_ID");
			DBUtil dbutil = new DBUtil(getServletContext());
			Vector relNameVector = dbutil.getReleaseStatus();
			String UpdateButton = request
			.getParameter("UpdateRelScheduleButton") == null ? ""
			: request.getParameter("UpdateRelScheduleButton");
			int releaseScheduleKey = Integer.parseInt(request
			.getParameter("releaseScheduleID") == null ? "0"
			: request.getParameter("releaseScheduleID"));
			ScheduleBean scheduleBean = new ScheduleBean();
			scheduleBean = dbutil
			.getRelScheduleInfo(releaseScheduleKey);

			String DeleteButton = request
			.getParameter("DeleteRelScheduleButton") == null ? ""
			: request.getParameter("DeleteRelScheduleButton");
%>
<html>
<head>
<link type="text/css" rel="stylesheet" href="styles/tracker_style.css">
<title>Update Release Schedule Information...</title>
<script>
			function checkForEmpty(ScheduleDescr,ServerName,ServerUserId,ServerUserPwd,Branch){
		  	
					// alert("obj.value.length"+obj.value);
			
				ScheduleDescr.value = trim(ScheduleDescr.value);
				ServerName.value = trim(ServerName.value);
				ServerUserId.value = trim(ServerUserId.value);
				ServerUserPwd.value = trim(ServerUserPwd.value);
				Branch.value = trim(Branch.value);
	
				if (ScheduleDescr.value.length == 0 )
				{
					alert("Please enter Schedule Name");
					ScheduleDescr.focus();
					return false;
				}
				if (ServerName.value.length == 0 )
				{
					alert("Please enter server name");
					ServerName.focus();
					return false;
				}
				if (ServerUserId.value.length == 0 )
				{
					alert("Please enter server user id.");
					ServerUserId.focus();
					return false;
				}
				if (ServerUserPwd.value.length == 0 )
				{
					alert("Please enter server password.");
					ServerUserPwd.focus();
					return false;
				}
				if (Branch.value.length == 0 )
				{
					alert("Please enter release branch.");
					Branch.focus();
					return false;
				}

				document.AddReleaseScheduleForm.submit();
				
		}
			

		function trim(sString)
			{
				sTrimmedString = "";
			   if (sString != "") {
				  var iStart = 0;
				  var iEnd = sString.length - 1;	
				  // var sWhitespace = " \t\f\n\r\v";
				  var sWhitespace = "   ";
		
	
				  while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) {
				  iStart++;
				  if (iStart > iEnd) 
					break;
			   }

			  // If the string not just whitespace
			  if (iStart <= iEnd) {
				 while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
					iEnd--;
				 sTrimmedString = sString.substring(iStart,++iEnd);
			  }
		   }
		   return sTrimmedString;
		 }


		</script>
</head>

<body>

<!-- 
<form name="updateRelease" method="post">
<table width=100%>
	<tr>
		<td width=100%><jsp:include page="HeaderNav_ReleaseObject.jsp" />
		</td>
	</tr>
</table>
</form>
 -->

<%
			//		System.out.println(">>>> Updatebutton :"+UpdateButton);
			if (UpdateButton.equals("Update")) {
		boolean updateSuccessFlag = false;
		String ScheduleDescr = request
				.getParameter("ScheduleDescr") == null ? ""
				: request.getParameter("ScheduleDescr");
		String ServerName = request.getParameter("ServerName") == null ? ""
				: request.getParameter("ServerName");
		String ServerUserId = request
				.getParameter("ServerUserId") == null ? ""
				: request.getParameter("ServerUserId");
		String ServerUserPwd = request
				.getParameter("ServerUserPwd") == null ? ""
				: request.getParameter("ServerUserPwd");
		String Branch = request.getParameter("Branch") == null ? ""
				: request.getParameter("Branch");
		String ScheduleReleaseName = request
				.getParameter("ScheduleReleaseName") == null ? ""
				: request.getParameter("ScheduleReleaseName");
		int hiddenReleaseScheduleKey = Integer
				.parseInt(request
				.getParameter("hiddenReleaseScheduleKey") == null ? "0"
				: request
				.getParameter("hiddenReleaseScheduleKey"));

		updateSuccessFlag = dbutil.updateReleaseSchedule(ScheduleDescr, ServerName,
				ServerUserId, ServerUserPwd, Branch,
				ScheduleReleaseName, userid,
				hiddenReleaseScheduleKey);
		if(updateSuccessFlag == true){
%>
<script>
							alert("Release Schedule Details updated successfully.");
							window.opener.location.href="/st/ReleaseSchedule.jsp";
							window.close();
						</script>

<%		}else{
	%> 
	<script>
							alert("Same Release Schedule Name already exists, Kindly enter different name.");
							window.close();
							
						</script>
	
	<% 
			}
	}
			if (DeleteButton.equals("Delete")) {
		int hiddenReleaseScheduleKey = Integer
				.parseInt(request
				.getParameter("hiddenReleaseScheduleKey") == null ? "0"
				: request
				.getParameter("hiddenReleaseScheduleKey"));

		dbutil.deleteReleaseSchedule(hiddenReleaseScheduleKey);
%>
<script>
							alert("Release Schedule deleted successfully.");
							window.opener.location.href="/st/ReleaseSchedule.jsp";
							window.close();
						</script>

<%
}
%>




<form name="EditReleaseScheduleForm" action="EditReleaseSchedule.jsp"
	method="post">

<table cellpadding="0" cellspacing="1" width="75%"
	style="BORDER:#000000 1px solid" align='center' colspan=2>
	<input type="hidden" name="hiddenReleaseScheduleKey"
		value="<%= scheduleBean.getReleaseScheduleKey() %>">
	<tr bgcolor=#000077>
		<td class=smallfonthead align=left colspan=2><b>Edit Release
		Schedule Information</b></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Schedule Name</td>
		<td class=bodyblue align=left colspan="1" width="70%"><input
			type=text name="ScheduleDescr" size="40"
			value='<%= scheduleBean.getScheduleDescr() %>'></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Server Name</td>
		<td class=bodyblue align=left colspan="1" width="70%"><input
			type=text name="ServerName" size="40"
			value='<%= scheduleBean.getServerName() %>'></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Server User
		Id</td>
		<td class=bodyblue align=left colspan="1" width="70%"><input
			type=text name="ServerUserId" size="40"
			value='<%= scheduleBean.getServerUserId() %>'></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Server
		Password</td>
		<td class=bodyblue align=left colspan="1" width="70%"><input
			type="password" name="ServerUserPwd" size="40"
			value='<%= scheduleBean.getServerUserPwd() %>'></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Branch</td>
		<td class=bodyblue align=left colspan="1" width="70%"><input
			type="text" name="Branch" size="40"
			value='<%= scheduleBean.getBranch() %>'></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class=bodyblue align=left colspan=1 width="30%">Select
		Release</td>
		<td class=bodyblue width="70%"><select name=ScheduleReleaseName>

			<%
					for (int i = 0; i < relNameVector.size(); i++) {
					ReleaseVO relbean = (ReleaseVO) relNameVector
							.elementAt(i);
			%>

			<option value='<%=	relbean.getReleaseName()%>'
				<%if(scheduleBean.getScheduleReleaseName().equals(relbean.getReleaseName())) {
				out.println("selected");				
			}else{
				out.println("");
			}
			%>><%=relbean.getReleaseName()%>
			</option>

			<%
			}
			%>
		</select></td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td colspan="1" class="bodyblue" width="30%">&nbsp</td>
		<td colspan="1" class="bodyblue" width="70%">&nbsp</td>
	</tr>
	<tr bgcolor=#EFEFEF>
		<td class="bodyblue" colspan="1" width="50%" align=right>
		<input
			type=submit class=whitebutton name=UpdateRelScheduleButton
			value="Update"
			onclick="return checkForEmpty(ScheduleDescr,ServerName,ServerUserId,ServerUserPwd,Branch)">
			</td>
		<td class="bodyblue" colspan="1" width="50%" align=right>
		<input
			type=submit class=whitebutton name=DeleteRelScheduleButton
			value="Delete"></td>
	</tr>

</table>
</form>


</body>
</html>

<%
	}
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
